package com.jxaummd.mushroom.main.data.data;


import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.jxaummd.mushroom.core.app.account.AccountManager;
import com.jxaummd.mushroom.core.base.data.DataSource;
import com.jxaummd.mushroom.core.util.net.RestClient;
import com.jxaummd.mushroom.core.util.tool.storage.UniversityPreference;
import com.jxaummd.mushroom.core.util.tool.time.MTimeUtils;
import com.jxaummd.mushroom.main.data.beam.DataBean;
import com.jxaummd.mushroom.main.data.beam.MbInfoBean;
import com.jxaummd.mushroom.main.data.presenter.DataPresenter;

import java.util.LinkedList;
import java.util.List;

import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;

public class DataDataServe {
    private LinkedList<AbstractFlexibleItem> mList = new LinkedList<>();

    /**
     * 获取数据集
     *
     * @return
     */
    public LinkedList getDataList() {
        return mList;
    }

    /**
     * 添加数据
     *
     * @param item
     * @return
     */
    public DataDataServe addData(AbstractFlexibleItem item) {
        mList.add(item);
        return this;
    }

    /**
     * 请求蘑菇箱的所有数据的
     */
    public static void requestData(int mbid, DataSource.Callback callback) {
        RestClient.builder().url("http://47.107.183.2/mushroom/getdata")
                .params("mbid", mbid)
                .success(response -> {
                    MbInfoBean bean = JSONObject.parseObject(response, MbInfoBean.class);
                    if (bean.getStatus() == 0) {
                        LogUtils.d("I get time ->2018-11-20 02:47:51" + bean.getData().get(0).getMb_time() + bean.getData().size());
                        callback.onDataLoaded(bean.getData());
                    }
                })
                .build()
                .get();
    }


}
